package com.ruipengkj.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ruipengkj.bean.TOrderSummary;
import com.ruipengkj.commons.dao.GenericDao;
import com.ruipengkj.dao.TOrderSummaryDao;

@Repository
public class TOrderSummaryDaoImpl extends GenericDao<TOrderSummary,String> implements TOrderSummaryDao{

//	public List<TOrderSummary> findByWorkShiftID(String WorkShiftID) {
//		return querySQL2("SELECT o.WorkShiftID AS workShiftID, " +
//				"COUNT(*) AS Counts, SUM(o.DiscountAmount) AS DiscountAmounts," +
//				"SUM(CASE WHEN o.PayWay = 7 THEN o.PayedAmount ELSE 0 END) AS CashAmounts," +
//				"SUM(CASE WHEN o.PayWay = 8 THEN o.PayedAmount ELSE 0 END) AS CardAmounts," +
//				"SUM(CASE WHEN s.WorkShiftID = '"+WorkShiftID+"' THEN s.AMount ELSE 0 END) AS RechangeAmounts " +
//				"FROM ruipeng_tb_torder AS o JOIN ruipeng_tb_tshopcharge AS s WHERE o.WorkShiftID = '"+WorkShiftID+"' ;"
//				, TOrderSummary.class, null);
//	}
	public List<TOrderSummary> findByWorkShiftID(String WorkShiftID) {
		String sql = "SELECT * FROM " +
		"(SELECT '"+WorkShiftID+"' AS workShiftID," +
		"COUNT(*) AS Counts, SUM(o.DiscountAmount) AS DiscountAmounts," +
		"SUM(CASE WHEN o.PayWay = 7 THEN o.PayedAmount ELSE 0 END) AS CashAmounts," +
		"SUM(CASE WHEN o.PayWay = 8 THEN o.PayedAmount ELSE 0 END) AS CardAmounts " +
		"FROM ruipeng_tb_torder AS o WHERE o.WorkShiftID = '"+WorkShiftID+"' ) " +
		"AS torder,(SELECT '"+WorkShiftID+"' AS WorkShiftID, " +
		"SUM(money) AS RechargeAmount FROM ruipeng_tb_tshoprecharge WHERE WorkShiftID = '"+WorkShiftID+"') " +
		"AS tshopRecharge WHERE torder.workShiftID = tshopRecharge.workShiftID";
		System.out.println(sql);
		return querySQL2(sql, TOrderSummary.class, null);
	}
	
}
